<?php

namespace utils;
/**
 * Created by Chukintang on 2018/5/18 17:27.
 */
class PwdUtil
{
    //密钥
    const KEY = '746a310133de26537dd4e7683575fa58';

    const IV = '746a310133de2653';

    const METHOD = 'AES-256-CBC';
    /**
     * 加密
     * @desc 加密
     */
    public static function encode($data,$method = 'AES-256-CBC', $key = self::KEY, $iv = self::IV)
    {
        if(is_array($data)){
            $data = serialize($data);
        }elseif(!is_string($data)){
            return false;
        }
        return openssl_encrypt($data,$method,$key,0,$iv);
    }

    /**
     * 解密
     * @desc 解密
     */
    public static function decode($data,$method = 'AES-256-CBC', $key = self::KEY, $iv = self::IV)
    {
        return openssl_decrypt($data,$method,$key,0,$iv);
    }
}